/*** Created by huangxuehua on 2017/11/23.*/
/** 首页轮播图片详情页   **/
/****右上角分享按钮弹出框*****/
//userInfo.refereId= nUtils.getUrlParam("refereid");//获取推荐人信息
userInfo.userId= nUtils.getUrlParam("userid")//客户id
var toastLoading = new auiToast({});
var mySwiper = undefined;
//
Vue.use(VueLazyload, {  //图片懒加载
    preLoad: 1.3,
    error: '../../icon/one.jpg',
    loading: '../../icon/loading.gif',
    attempt: 1
});

var xpHome = new Vue({
    el:'#allApp',
    data:{
        imgBaseUrl:nUrls.imgBaseUrl, //商品图片路径
        imgFBaseUrl:nUrls.imgFBaseUrl,//评论、售后商品路径
        goodsNum:1,
        goodsInfo:{},  //商品详情
        goodsArb:[],//商品属性
        choseGoodsArb:[],//用户选择商品分类信息
        attrGoodsInfo:{},//  获得商品属性
        lastCommentInfo:{},//获得最后一条评论
        isCollect:0 ,//是否已经评论
        commentCount:{},// 评价总数量
        refUserInfo:{}, //推荐人信息
        bigImgArr:[],//大图列表
        bigImgIndx:1,//当前显示图片
        bigImgShowSrc:'',//当前大图
        isShowSwiper:false, //是否显示大图,
        goBuyOrGoShop:1,//1 加入购物车   2 立即购买
        couponListInfo:{}//获取优惠券信息
    },
    methods:{
        getImage:function(url){//加载图片  处理 url为空 加载出错
            if(url){
                return xpHome.imgBaseUrl+url;
            }
        },
        getFImage:function(url){//加载图片  处理 url为空 加载出错
            if(url){
                return url;
            }
        },
        changeTab:function(flag,isTop){//切换tab
            $("#xiangqing").removeClass("aui-active");
            $("#pingjia").removeClass("aui-active");
            $("#shangpin").removeClass("aui-active");
            switch(flag){
                case "shangpin":
                    $("#shangpin").addClass("aui-active");
                    if(isTop){
                        document.documentElement.scrollTop = 0;
                        document.body.scrollTop = 0;
                    }
                    break;
                case "pingjia":
                    $("#pingjia").addClass("aui-active");
                    if(isTop){
                        document.documentElement.scrollTop = 400;
                        document.body.scrollTop = 400;
                    }
                    break;
                case "xiangqing":
                    $("#xiangqing").addClass("aui-active");
                    //xpHome.goodsInfo.desc_slt="";
                    if(isTop){
                        document.documentElement.scrollTop = 900;
                        document.body.scrollTop = 900;
                    }
                    break;
                default:
                    break;
            }
        },
        getImageComment:function(url){//加载图片  处理 url为空 加载出错
            if(url){
                return nUrls.imgFBaseUrl+url;
            }
        },
        getDate:function(time){//时间  年月日
            return nUtils.dateFormat(time);
        },
        getDateType:function(time){  //时间格式.
            return nUtils.dateType(time);
        },
        getCouponPrice:function(price){ //替换 价格去零
            if(price){
                var prices = price.replace(".00","");
                return   prices;
            }
        },
        getPrice:function(price){//价格样式
            if(price){
                var prices = price.split(".");
                if(prices.length >=2){
                    return  '￥'+prices[0]+'.</span><span class="aui-font-size-14">'+prices[1];
                }else{
                    return   '￥'+price;
                }
            }
        },
        gohome:function(){//首页
            window.location.href = "../../index.html";
        },
        muchOrLess:function(type){//添加或减少 商品   type 1添加  -1减少
            if(type == 1){//添加  需要判断小于物品的总数
                xpHome.goodsNum +=1;
            }else{//减少  判断 >=1
                if(xpHome.goodsNum >1){
                    xpHome.goodsNum -=1;
                }
            }
        },
        getRefUser:function(){   //获取推荐人信息
            var data ={
                "refereid": nUtils.getUrlParam("refereid")
            }
            $.ajax({
                url:nUrls.getRefUserInfo, //获得商品属性信息
                type:"POST",
                data:data,
                success:function(data){
                    var result=eval('('+data+')') ;//JOSN 数据转 JOSN对象
                    if(result && result.code===200){
                    xpHome.refUserInfo=result.data;
                        window.localStorage.setItem("tuiJianUserInfo",JSON.stringify( xpHome.refUserInfo))
                    }
                    //console.log("= xpHome.refUserInfo=", xpHome.refUserInfo);
                },
                error:function(){
                    console.log("获取推荐人信息失败")
                }
            })
        },
        goActivity:function(){   //跳转到活动详情页面
            window.location.href="../activity.html"
        },
        getCanCoupon:function(){ //获取可领取优惠券数据
            $.ajax({
                url:nUrls.getCanAllCoupon,
                type:"POST",
                success:function(data){
                    var result=eval('('+data+')') ;//JOSN 数据转 JOSN对象
                    if(result && result.code===200){
                        xpHome.couponListInfo=result.data;
                    }
                    console.log("= xpHome.couponListInfo=", xpHome.couponListInfo);
                },
                error:function(){
                    console.log("获取优惠券信息失败")
                }
            })
        },
        getClickCoupon:function(idx){//点击领取优惠券
            if(xpHome.couponListInfo[idx].isHave == 1){
                var toast = new auiToast(); //初始化toast事件
                toast.custom({
                    title: "已经领取",
                    html:"",
                    duration: 1000
                })
                return;
            }
            var data={
                "userid":userInfo.userid,
                "access_token":userInfo.access_token,
                "data[couponid]":xpHome.couponListInfo[idx].coupon_id
            }
            $.ajax({
                url:nUrls.getMyCoupon,
                type:"POST",
                data:data,
                success:function(data){
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                       xpHome.getCanCoupon();
                            var toast = new auiToast(); //初始化toast事件
                            toast.custom({
                                title: "领取成功",
                                html:"",
                                duration: 1000
                            })
                    }
                },
                error: function () {
                    console.log("获取信息出错");
                }
            })
        },
        getGoodsInfo:function(){  //获得商品信息
            var data = {
                goods_id:nUtils.getUrlParam("id"),
            };
            $.ajax({
                url: nUrls.getGoodsInfo, //获得商品属性信息
                type: "POST",
                data: data,
                success: function (data) {
                    var result = eval('(' + data + ')');//JOSN 数据转 JOSN对象
                    if (result && result.code === 200) {
                        $("#aui-slide2").hide();
                        xpHome.goodsInfo = result.data;
                        xpHome.goodsArb = xpHome.goodsInfo.attrValueGoods;
                        console.log(xpHome.goodsInfo)
                        //xpHome.TchangeImg(xpHome.goodsInfo.Typename)

                            xpHome.goodsInfo.desc_slt=xpHome.goodsInfo.desc_text;
                            console.log("xpHome.goodsInfo.desc_text",xpHome.goodsInfo.desc_text)

                        console.log("-- xpHome.goodsInfo-", xpHome.goodsInfo)
                        //console.log("-- xpHome.goodsInfo.is_gift-", xpHome.goodsInfo)

                        //console.log("---xpHome.goodsInfo.attrValueGoods.reverse()--",xpHome.goodsArb);
                        window.localStorage.setItem("GoodsInfo",JSON.stringify( xpHome.goodsInfo));//发送到评论页
                        //xpHome.sortImg();//banner 图片升序 排序
                        //轮播  解决延迟加载
                        setTimeout(function(){  
                            $("#aui-slide2").show();
                            var slide2 = new auiSlide({
                                container:document.getElementById("aui-slide2"),
                                //"width":360,
                                "height":'auto',
                                "speed":300,
                                "autoPlay":0, //自动播放
                                "pageShow":true,
                                "loop":true,
                                "pageStyle":'dot',
                                'dotPosition':'center'
                            });
                        },(300));

                    }
                    //console.log("=getGoodsInfo=",result);
                },
                error:function(){
                    console.log("获取商品信息失败");
                }
            })
        },
        //sortImg:function(){//banner 图片排序 升序排序
        //    if(xpHome.goodsInfo.goodsGallImages){
        //        xpHome.goodsInfo.goodsGallImages.sort((a,b)=>{
        //            return a.sort_number > b.sort_number;
        //        });
        //    }
        //},
        choseArb:function(idx,fid,id,attrValueName){//选择属性   属性点击事件
            toastLoading.loading({
                title:"加载中",
            },function(ret){
            });
            $("#f"+fid+">li input").removeClass("aui-btn-type");
            $("#c"+id).addClass("aui-btn-type");
            xpHome.choseGoodsArb[idx] = {
                "fatherid:":fid,
                "chirdid":id,
                "attrValueName":attrValueName
            };

            //选择的属性个数 与 商品属性个数一致才可提交
            if(xpHome.goodsArb.length != xpHome.choseGoodsArb.length ){
                return;
            }

            var ids = "";
            for(var v=0;v<xpHome.choseGoodsArb.length;v++){
                var temp = xpHome.choseGoodsArb[v];
                if(temp){
                    ids+= temp.chirdid;
                }
            }
            var data={
                "data[attrValue]": ""+ids
            }
            $.ajax({
                url:nUrls. attrGetGoodsInfo,
                type:"POST",
                data:data,
                success:function(data) {
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                        xpHome.attrGoodsInfo = result.data;

                        //console.log("====sss===",xpHome.attrGoodsInfo)
                    } else if(result && result.code == 500){  //没有此商品,需要改进
                        xpHome.attrGoodsInfo.goods_number=0
                    }
                    toastLoading.hide();
                },
                error:function(){
                    console.log("获取属性信息失败")
                }
            })

        },
        addCollect:function(){     //添加收藏  取消收藏
            if(xpHome.isCollect==0) {
                var data = {
                    "data[goods_id]": xpHome.goodsInfo.goods_id,
                }
                $.ajax({
                    url: nUrls.getAddCollect,
                    type: "POST",
                    data: data,
                    success: function (data) {
                        var result = eval('(' + data + ')');
                        if (result && result.code == 200) {
                            var toast = new auiToast(); //初始化toast事件
                            toast.custom({
                                title: "添加收藏",
                                html: '',
                                duration: 1000
                            })
                            xpHome.isCollect = 1;
                        }
                    },
                    error: function () {
                        console.log("添加到收藏出错");
                    }
                })
            }else if(xpHome.isCollect==1){
                var data={
                    "data[goods_id]":xpHome.goodsInfo.goods_id,
                }
                $.ajax({
                    url:nUrls.getDelCollect,
                    type:"POST",
                    data:data,
                    success: function (data) {
                        var result = eval('(' + data + ')');
                        if (result && result.code == 200) {
                            var toast = new auiToast(); //初始化toast事件
                            toast.custom({
                                title: "取消收藏",
                                html: '',
                                duration: 1000
                            })
                            xpHome.isCollect = 0;
                        }
                    },
                    error: function () {
                        console.log("取消收藏出错");
                    }
                })
            }
        },
        addCart:function(type){//添加到购物车  type =1 属性页面  为空详情页面
            if(xpHome.goodsInfo.goods_number<=0){
                var toast = new auiToast(); //初始化toast事件
                toast.custom({
                    title: "库存为零",
                    html: '',
                    duration: 2000
                });
                return;
            }
            xpHome.goBuyOrGoShop = 1;
            if(xpHome.goodsInfo.is_single==1){//是单品
                //console.log("---xpHome.goodsInfo.is_single---",xpHome.goodsInfo.is_single)
                var data = {//添加到购物车成功将数据传入后台
                    "userid":userInfo.userid,//客户Id
                    "access_token":userInfo.access_token,
                    "data[goods_id]":xpHome.goodsInfo.goods_id,
                    "data[refere_id]":nUtils.getUrlParam("refereid"),
                    "data[cart_number]":xpHome.goodsNum
                };
                $.ajax({
                    url:nUrls.addShopCart,
                    type:"POST",
                    data:data,
                    success: function (data) {
                        //console.log(data)
                        var result = eval('(' + data + ')');
                        if (result && result.code == 200) {
                            var toast = new auiToast(); //初始化toast事件
                            toast.custom({
                                title: "已添加到购物车",
                                html: '',
                                duration: 2000
                            })
                        }
                    },
                    error: function () {
                        console.log("添加到购物车出错");
                    }
                })
                return;
            }

            var display=  $(".options").css("display");
            if(display == "none"){
                //document.documentElement.scrollTop = 0;
                $("#detailBody").css("overflow","hidden");
                $(".options").css("display","block");
                touchMoveCant(".options");
                // type为空 赋 默认值 开始
                if(!type){
                    if(xpHome.goodsArb.length>0){//有可选属性
                        //以下方式 效率低不采用
                        var arbList = xpHome.goodsArb;
                        for(var i=0;i<arbList.length;i++){
                            var temp = arbList[i].children;
                            for(var j=0;j<temp.length;j++){
                                var vv = temp[j];
                                if(vv.check == 1){
                                    xpHome.choseArb(i,vv.attr_id,vv.attr_value_id,vv.attr_value_name);
                                    break;
                                }
                            }
                        }
                    }
                }
                // type为空 赋 默认值 结束
                return;
            }
            //添加购物车之前的判断  非单品
            if(xpHome.choseGoodsArb.length < xpHome.goodsArb.length){//用户未选择或者少选择 分类
                if(type == 1){//显示 选择分类后 用户依然没选择
                    var toast = new auiToast(); //初始化toast事件
                    toast.custom({
                        title: "请选择分类",
                        html: '',
                        duration: 2000
                    })
                    return;
                }

            }else {  //确定加入购物车
                if(!xpHome.attrGoodsInfo.goods_number){ //库存为零，提示框
                    var toast = new auiToast(); //初始化toast事件
                    toast.custom({
                        title: "库存为零",
                        html: '',
                        duration: 2000
                    })
                    return;
                }
                var data = {//添加到购物车成功将数据传入后台
                    "userid":userInfo.userid,//客户Id
                    "access_token":userInfo.access_token,
                     "data[goods_id]":xpHome.attrGoodsInfo.goods_id,
                    "data[refere_id]":nUtils.getUrlParam("refereid"),
                    "data[cart_number]":xpHome.goodsNum
                };
                $.ajax({
                    url:nUrls.addShopCart,
                    type:"POST",
                    data:data,
                    success: function (data) {
                        //console.log("+===+++++",data);
                        var result = eval('(' + data + ')');
                        if (result && result.code == 200) {
                            var toast = new auiToast(); //初始化toast事件
                            toast.custom({
                                title: "已添加到购物车",
                                html: '',
                                duration: 2000
                            });
                            $(".options").css("display","none");
                            $("#detailBody").css("overflow","auto");
                        }

                    },
                    error: function () {
                        console.log("添加购物车出错");
                    }
                })
            }
        },
        getCommentCount:function(){ //评价总数量
            var data={
                "data[goods_id]":nUtils.getUrlParam("id"), //产品Id
            }
            $.ajax({
                url:nUrls.getCommentCountUrl,
                type:"POST",
                data:data,
                success: function (data) {
                    //console.log("+===+++++",data);
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                        xpHome.commentCount=result.data;
                        window.localStorage.setItem("commentcount",JSON.stringify(xpHome.commentCount))  //评论数量
                        //console.log("+++++++  xpHome.commentCount+++++++++++",  xpHome.commentCount)
                    }
                },
                error: function () {
                    console.log("获取评论信息数量出错");
                }
            })
        },
        getLastComment:function(){  //获得最后一条评论
            var data={
                "data[goods_id]":nUtils.getUrlParam("id"), //产品Id
            }
            $.ajax({
                url:nUrls.getLastCommitInfo,
                type:"POST",
                data:data,
                success: function (data) {
                    //console.log("+===+++++",data);
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                        xpHome.lastCommentInfo=result.data
                        //console.log("++++++++++++++++++",xpHome.lastCommentInfo)
                    }
                },
                error: function () {
                    console.log("获取评论信息失败");
                }
            })
        },
        getSartNum:function(rank){//获取星星个数
            if(rank){
               return parseInt(rank) ;
            }
            return 0;
        },
        goComment:function(){//评论详情页
            window.location.href="../comment/comment.html"
        },
        getGoodsCollectInfo:function(){  //查看商品是否收藏
            var data={
                  "data[goods_id]	":nUtils.getUrlParam("id"),
            }
            $.ajax({
                url:nUrls.getGoodsIsCollect,
                type:"POST",
                data:data,
                success: function (data) {
                    //console.log("+===+++++",data);
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                        xpHome.isCollect=result.data
                        //console.log("-- xpHome.isCollect--", xpHome.isCollect)
                    }
                },
                error: function () {
                    console.log("添加收藏失败");
                }
            })
        },
        goShopCart:function(){
            window.location.href="../shop_cart.html"
        },
        goBuy:function(type){//立即购买
            if(xpHome.goodsInfo.goods_number<=0){
                var toast = new auiToast(); //初始化toast事件
                toast.custom({
                    title: "库存为零",
                    html: '',
                    duration: 2000
                })
                return;
            }
            xpHome.goBuyOrGoShop = 2;
            if(xpHome.goodsInfo.is_single==1){//是单品
                var tempGoods = xpHome.goodsInfo;
                tempGoods.goods_number=xpHome.goodsNum;//购买数量
                window.localStorage.setItem("choseGoods",JSON.stringify(tempGoods));
                window.location.href = "../buy.html?flag=atonce";//立即购买
                return;
            }
            var display=  $(".options").css("display");
            if(display == "none"){
                //document.body.scrollTop = 0;
                //document.documentElement.scrollTop = 0;
                $("#detailBody").css("overflow","hidden");
                $(".options").css("display","block");
                touchMoveCant(".options");
                // type为空 赋 默认值 开始
                if(!type){
                    if(xpHome.goodsArb.length>0){//有可选属性
                        //以下方式 效率低不采用
                        var arbList = xpHome.goodsArb;
                        for(var i=0;i<arbList.length;i++){
                            var temp = arbList[i].children;
                            //console.log("+++++",temp);
                            for(var j=0;j<temp.length;j++){
                                var vv = temp[j];
                                if(vv.check == 1){
                                    xpHome.choseArb(i,vv.attr_id,vv.attr_value_id,vv.attr_value_name);
                                    break;
                                }
                            }
                        }
                    }
                }
                // type为空 赋 默认值 结束
                return;
            }
            if(xpHome.choseGoodsArb.length < xpHome.goodsArb.length){//用户未选择或者少选择 分类

                if(type == 1){//显示 选择分类后 用户依然没选择
                    var toast = new auiToast(); //初始化toast事件
                    toast.custom({
                        title: "请选择分类",
                        html: '',
                        duration: 2000
                    })
                    return;
                }
            }else{//用户已经全部选择了分类
                if(!xpHome.attrGoodsInfo.goods_number){ //库存为零，提示框
                    var toast = new auiToast(); //初始化toast事件
                    toast.custom({
                        title: "库存为零",
                        html: '',
                        duration: 2000
                    })
                    return;
                }
                var choseGoods = {
                    goods_id:xpHome.attrGoodsInfo.goods_id,//每种属性的商品id
                    goods_name: xpHome.attrGoodsInfo.goods_name,//商品名称
                    goods_image :xpHome.attrGoodsInfo.goods_image,//商品图片
                    shop_price:parseFloat(xpHome.attrGoodsInfo.shop_price),//商品价格
                    goods_number:xpHome.goodsNum,//购买数量
                    goods_arb:xpHome.choseGoodsArb,//用户选择的商品分类
                    goods_desc:xpHome.attrGoodsInfo.goods_desc,//商品描述
                    attrText: xpHome.goodsInfo .attrText
                }; //用户选择商品信息
                window.localStorage.setItem("choseGoods",JSON.stringify(choseGoods));
                window.location.href = "../buy.html?flag=atonce";//立即购买
            }
        },
        lookImg:function(index){//放大
            //console.log("==index==",index);
            xpHome.bigImgIndx = index + 1; //当前显示
            xpHome.showSwiper(index);
            xpHome.bigImgShowSrc = $(this).attr("src");
        },
        showSwiper: function(idx) {    //图片滑动
            xpHome.isShowSwiper = true;
            document.documentElement.scrollTop = 0;
            document.body.scrollTop = 0;
            touchMoveCant("#mySwiper");
            $("#detailBody").css("overflow","hidden");
            this.$nextTick(function() {
                if(mySwiper) {
                    mySwiper.destroy();
                    mySwiper = undefined;
                }
                mySwiper = new Swiper("#mySwiper", {
                    direction: 'horizontal',
                    loop: false,
                    zoom: true,
                    onSlideChangeEnd: function(swiper) { //水平滑动切换
                        xpHome.bigImgIndx = swiper.activeIndex + 1; //滚动显示
                    }
                });
                if(idx === 0) {
                    mySwiper.slideTo(1, 0);
                    mySwiper.slideTo(0, 0);
                } else {
                    mySwiper.slideTo(idx, 0);
                }
            });
        },
        closeSwiper: function() {
            $("#detailBody").css("overflow","auto");
            xpHome.isShowSwiper = false;
        },
        goOnLine:function(){  //断网刷新
            nUtils.onLine();
        },

        TchangeImg:function(Typename){
            //缩约图与高清图替换
            if(Typename=='P7'){
                var SlImgUrl = [
                    '../P7gqt/1.png',
                    '../P7gqt/2.png',
                    '../P7gqt/3-1.png',
                    '../P7gqt/3-2.gif',
                    '../P7gqt/3-3.png',
                    '../P7gqt/4.gif',
                    '../P7gqt/5.gif',
                    '../P7gqt/6.gif',
                    '../P7gqt/7.gif',
                    '../P7gqt/8.png',
                    '../P7gqt/9.gif',
                    '../P7gqt/10.png',
                    '../P7gqt/11.gif',
                    '../P7gqt/12.png',
                    '../P7gqt/13.gif',
                    '../P7gqt/14.png',
                    '../P7gqt/15.png',
                    '../P7gqt/16.png',
                    '../P7gqt/17.png',
                    '../P7gqt/18.gif',
                    '../P7gqt/19.gif',
                    '../P7gqt/20.gif',
                    '../P7gqt/21.png',
                    '../P7gqt/22.png',
                    '../P7gqt/23.png',
                    '../P7gqt/24.png',
                    '../P7gqt/25.png',
                    '../P7gqt/26.png'
                ];
            } else if(Typename=='P8') {
                var SlImgUrl = [
                    '../P8gqt/1.png',
                    '../P8gqt/2.gif',
                    '../P8gqt/3.png',
                    '../P8gqt/4.png',
                    '../P8gqt/5.gif',
                    '../P8gqt/6.png',
                    '../P8gqt/7.gif',
                    '../P8gqt/8.png',
                    '../P8gqt/9.gif',
                    '../P8gqt/9-1.gif',
                    '../P8gqt/10.png',
                    '../P8gqt/11.png',
                    '../P8gqt/12.gif',
                    '../P8gqt/13.gif',
                    '../P8gqt/14.gif',
                    '../P8gqt/15.png',
                    '../P8gqt/16.png',
                    '../P8gqt/17.png',
                    '../P8gqt/18.png',
                    '../P8gqt/19.gif',
                    '../P8gqt/20.gif',
                    '../P8gqt/21.png',
                    '../P8gqt/22.png',
                    '../P8gqt/23.png',
                    '../P8gqt/24.gif',
                    '../P8gqt/25.png',
                    '../P8gqt/26.png',
                    '../P8gqt/26-1.gif',
                    '../P8gqt/27.png',
                    '../P8gqt/28.gif',
                    '../P8gqt/29.gif',
                    '../P8gqt/30.png',
                    '../P8gqt/31.png',
                    '../P8gqt/32.png',
                    '../P8gqt/33.png',
                    '../P8gqt/34.png',
                    '../P8gqt/35.png',
                    '../P8gqt/36.png'
                ];
            }

            var imgARR = new Array;
            var eleARR = new Array;
            for(var i = 0; i<SlImgUrl.length;i++) {
                var s = i+1
                var ele = document.querySelector('.thumbnails'+s)
                eleARR.push(ele);

                var img = new Image();
                img.src = SlImgUrl[i];
                imgARR.push(img);
            }
            console.log(eleARR)
            for(var i = 0; i<imgARR.length;i++) {

                (function(i){
                    imgARR[i].onload = function(){
                        eleARR[i].src = imgARR[i].src;
                    }

                })(i)


            }
        }
    }
});

$(function(){
    xpHome.getGoodsInfo();//获取商品信息
    xpHome.getCommentCount();//获得评论数量
    xpHome.getLastComment();//退后一条评论
    xpHome.getGoodsCollectInfo();//获取商品是否评论
    xpHome. getRefUser();//获取推荐人信息
    xpHome.getCanCoupon();//获取优惠券信息
    window.localStorage.setItem("choseAddress",""); //清空选择地址
})

$(".coupon").click(function() {
    if(!xpHome.couponListInfo){
        console.log("xpHome.couponListInfo",xpHome.couponListInfo)
        $(".couponMain").css({
            //"background": "#555",
            //"opacity": "0.6",
            "display": "block"
        })
    }

    touchMoveCant(".couponMain");
})
$(".closeBtn").click(function(){
    $(".couponMain").css({
        "display": "none"
    })
})

$("#coverPic").click(function(){  //遮罩层显示
        //document.documentElement.scrollTop = 0;
        //document.body.scrollTop = 0;
    $("#detailBody").css("overflow", "hidden");
    $("#shareDiv").show();
    $("#shareDiv").css({
        "background":"#555",
        "opacity":"0.6",
        "display": "block",
    });
    touchMoveCant("#shareDiv");
});
function touchMoveCant(ele){//ios 等其他型号手机 滑动问题
    document.querySelector(ele).addEventListener("touchmove", function(e){
        e.preventDefault();
    });
}
$("#shareDiv").click(function(){
    $("#shareDiv").hide();
    $("#detailBody").css("overflow","auto");
})
$("#fenXiang").click(function(){ //遮罩层隐藏，并分享
    $("#shareDiv").hide();
    $("#detailBody").css("overflow","auto");

})



/***底部服务弹窗****/
apiready = function(){
    api.parseTapmode();
}
var actionsheet = new auiActionsheet();
function openServe() {
    actionsheet.init({
        frameBounces: true,//当前页面是否弹动，（主要针对安卓端）
        title: "",
        cancelTitle: '确定',
        // destructiveTitle:'红色警告按钮',
        buttons: ['顺丰快递', '24小时发货', '不支持7天无理由退货']
    })
}
$(function(){
    $('div.goHome').click(function(){
        window.history.go(-1);
        //window.location.href="../../index.html"
    });

    //$(".popUp").click(function(){
    //    $(".options").css("display","block");
    //});
    $(".closeBtn").click(function(){
        $(".options").css("display","none");
        $("#detailBody").css("overflow","auto");
    })
});
$(function(){//返回顶部
    $("#back-to-top").hide();
    window.onscroll = function(){
        // 谷歌不识别document.documentElement.scrollTop，必须要加上document.body.scrollTop；
        var height =  document.documentElement.scrollTop||document.body.scrollTop;
        if(height<=500){
            $("#back-to-top").hide();
        }else{
            $("#back-to-top").show()
        }

        if(height<350){//商品
            xpHome.changeTab("shangpin");
        }else if(height >=350 && height <900 ){//评价
            xpHome.changeTab("pingjia");
        }else{//详情
            xpHome.changeTab("xiangqing");
        }
    };
});



